// LucasLehmer, Performs the Lucas Lehmer algorithm
// Copyright (C) 2014  David McCloskey
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef __exceptions_h__
#define __exceptions_h__

#include <stdint.h>
#include <stdexcept>
#include <sstream>

template <class T>
static inline std::string convert_value(T value)
{
	std::stringstream stream;
	stream << value;
	return stream.str();
}
    
#define DEFINE_EXCEPTION(name, base)			\
	class name : public base					\
	{											\
	public:										\
		explicit name()							\
		{ }										\
												\
		virtual ~name() NOEXCEPT				\
		{ }										\
	};

#define DEFINE_DATA_EXCEPTION(name, base, type)		\
	class name : public base						\
	{												\
	private:										\
		type m_Value;								\
													\
	public:											\
		explicit name(type value)					\
		{ }											\
													\
		virtual ~name() NOEXCEPT					\
		{ }											\
	public:											\
		type get_value() const { return m_Value; }	\
	};

DEFINE_DATA_EXCEPTION(unknown_algorithm, std::exception, algorithm_t);
DEFINE_DATA_EXCEPTION(unknown_argument, std::exception, const char*);
DEFINE_DATA_EXCEPTION(invalid_exponent, std::exception, const char*);
DEFINE_EXCEPTION(not_implemented, std::exception);

#endif  // __exceptions_h__
